package net.opslog.web.client.widgets;

import java.util.List;

import net.opslog.web.client.models.LogEntry;

import com.google.gwt.cell.client.SafeHtmlCell;
import com.google.gwt.core.client.GWT;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.cellview.client.CellTable;
import com.google.gwt.user.cellview.client.Column;
import com.google.gwt.user.cellview.client.TextColumn;

public class LogTable extends Composite {

	private static LogTableUiBinder uiBinder = GWT
			.create(LogTableUiBinder.class);
	@UiField(provided = true)
	CellTable<LogEntry> cellTable = new CellTable<LogEntry>();

	private String logFormat = "%message";
	interface LogTableUiBinder extends UiBinder<Widget, LogTable> {
	}

	public LogTable() {
		initWidget(uiBinder.createAndBindUi(this));
		final SafeHtmlCell rawCell = new SafeHtmlCell();

		Column<LogEntry, SafeHtml> rawColumn = new Column<LogEntry, SafeHtml>(
				rawCell) {

			@Override
			public SafeHtml getValue(LogEntry logEntry) {
				SafeHtmlBuilder sb = new SafeHtmlBuilder();
				sb.appendHtmlConstant(logEntry.getRawEntry(logFormat));
				return sb.toSafeHtml();
			}

		};

		cellTable.addColumn(rawColumn, "Log");
	}

	public CellTable<LogEntry> getCellTable() {
		return cellTable;
	}

	public void setLogFormat(String logFormat) {
		this.logFormat = logFormat;
	}

	
}
